
import 'package:eq/eq.dart';
import 'package:eq/src/core.dart';
import 'package:eq/src/interpreter.dart';
import 'package:eq/src/utils.dart';
///核心模块
///
///使用最多的内置函数
///不依赖dart其他模块

void addCoreFunctions(Module module) {
  addNativeFunction("print", _print, module);
  addNativeFunction("instance", _instance, module);
}

Value _print(List<Value> args) {
  String temp = args.toString();
  temp = temp
      .replaceRange(0, 1, '')
      .replaceRange(temp.length - 2, temp.length - 1, '');
  print(temp);
  if (exitIso) {
    sendToHost(ScriptResult(code: 2, message: temp));
  }

  return Value(ValueType.NULL_VALUE, null);
}

Value _instance(List<Value> args) {
  if (args.length == 1) {
    return Value(ValueType.STRING_VALUE, getValueTypeName(args.first));
  }
  List<String> list = List.empty(growable: true);
  for (var a in args) {
    list.add(getValueTypeName(a));
  }
  return Value(ValueType.ARRAY_VALUE, list);
}
